package com.bjpowernode.controller;

import com.bjpowernode.entity.TTran;
import com.bjpowernode.query.TranQuery;
import com.bjpowernode.result.Result;
import com.bjpowernode.service.TranService;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class TranController {


    private final TranService tranService;

    @PostMapping("/api/tran")
    public Result createTran(@RequestBody TranQuery tranQuery) {
        int flag = tranService.createTran(tranQuery);

        return flag > 0 ? Result.OK() : Result.FAIL();
    }

    /**
     * 分页查询
     */
    @GetMapping("/api/tran")
    public Result tran(Integer current) {
        PageInfo<TTran> pageInfo = tranService.getTranByPage(current);

        return Result.OK(pageInfo);
    }

    /**
     * 查询交易明细
     */
    @GetMapping("/api/tran/{id}")
    public Result getTranById(@PathVariable Integer id) {
        TTran tTran = tranService.getTranById(id);
        return Result.OK(tTran);
    }
}
